package com.hibase.core.page.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.hibase.common.entity.ResponseModel;
import com.hibase.common.entity.user.LoginType;
import com.hibase.common.util.EntityUtil;
import com.hibase.core.page.entity.pagemenu.PageMenu;
import com.hibase.core.page.entity.pagemenu.vo.PageMenuInsertVO;
import com.hibase.core.page.entity.pagemenu.vo.PageMenuListVO;
import com.hibase.core.page.entity.pagemenu.vo.PageMenuSearchVO;
import com.hibase.core.page.entity.pagemenu.vo.PageMenuUpdateVO;
import com.hibase.core.page.entity.pagemenu.vo.PageMenuViewVO;
import com.hibase.core.page.service.pagemenu.PageMenuService;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 页面菜单配置表 前端控制器
 * </p>
 *
 * @author junk
 * @since 2021-03-31
 */
@RestController
@RequestMapping("/page-menu")
@Api(tags = "页面菜单配置表")
@SuppressWarnings({"unchecked", "rawtypes"})
public class PageMenuController{

    @Autowired
    private PageMenuService pageMenuService;
    
	@ApiOperation(value = "查询页面菜单配置表列表", httpMethod = "POST")
    @HibasePostRequestMapping(value = "selectPageMenuList")
    public ResponseModel<PageMenuListVO> selectPageMenuList(@RequestBody PageMenuSearchVO searchVO) {

        PageInfo result = pageMenuService.selectPageMenuList(searchVO);

        result.setList(EntityUtil.transform(result.getList(), PageMenuListVO.class));

        return ResponseModel.successMsg(result);
    }

    @ApiOperation(value = "新增页面菜单配置表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "insertPageMenu")
    public ResponseModel<String> insertPageMenu(@RequestBody PageMenuInsertVO insertVO) {

        PageMenu entity = EntityUtil.transform(insertVO, PageMenu.class);

        pageMenuService.savePageMenu(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "修改页面菜单配置表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "updatePageMenu")
    public ResponseModel<String> updatePageMenu(@RequestBody PageMenuUpdateVO updateVO) {

        PageMenu entity = EntityUtil.transform(updateVO, PageMenu.class);

        pageMenuService.savePageMenu(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "查询页面菜单配置表详情", httpMethod = "POST")
    @HibasePostRequestMapping(value = "viewPageMenuDetails")
    public ResponseModel<PageMenuViewVO> viewPageMenuDetails(@RequestBody OperationIdEntity operationidEntity) {

        return ResponseModel.successMsg(EntityUtil.transform(pageMenuService.viewPageMenu(operationidEntity.getId()), PageMenuViewVO.class));
    }

    @ApiOperation(value = "删除页面菜单配置表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/deletePageMenu")
    public ResponseModel<String> deletePageMenu(@RequestBody OperationIdEntity delete) {

        pageMenuService.deletePageMenu(delete.getId());

        return ResponseModel.successMsg();
    }

    @ApiOperation(value = "导出页面菜单配置表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/exportPageMenu")
	public ResponseModel<String> exportPageMenu(@RequestBody PageMenuSearchVO searchVO, HttpServletResponse response) {
		pageMenuService.exportPageMenu(searchVO, response);
		return ResponseModel.successMsg();
	}
    
    /**
     * @Title: PageMenuController
     * @Description: 同步resources pageConfig到pageMenu表中
     * @author TimBrian
     * @since 2021年11月10日 下午4:42:39
     */
	@ApiOperation(value = "同步resources pageConfig到pageMenu表中", httpMethod = "POST")
	@HibasePostRequestMapping("/syncPageConfigToPageMenu")
	public ResponseModel<String> syncPageConfigToPageMenu(@RequestBody LoginType loginType, HttpServletRequest request) {
		pageMenuService.syncPageConfigToPageMenu(loginType);
		return ResponseModel.successMsg();
	}
	
	/**
	 * @Title: PageMenuController
	 * @Description: 同步pageMenu表到resources pageConfig中
	 * @author TimBrian
	 * @since 2021年11月10日 下午4:50:23
	 */
	@ApiOperation(value = "同步pageMenu表到resources pageConfig中", httpMethod = "POST")
	@HibasePostRequestMapping("/syncPageMenuToPageConfig")
	public ResponseModel<String> syncPageMenuToPageConfig(@RequestBody LoginType loginType) {
		pageMenuService.syncPageMenuToPageConfig(loginType);
		return ResponseModel.successMsg();
	}
	
}